home *** CD-ROM | disk | FTP | other *** search
/ Czech Logic, Card & Gambling Games / Logické hry.iso / hry / Fish Fillets / script / share / prog_border.lua < prev    next >
Encoding:
Text File  |  2005-07-16  |  2.2 KB  |  75 lines

  1.  
  2. -- -----------------------------------------------------------------
  3. -- NOTE: uses 'small' and 'big' names for fishes
  4. local function canReport()
  5.     --TODO: don't talk when room is solved
  6.     return no_dialog() and small:isAlive() and big:isAlive()
  7. end
  8. -- -----------------------------------------------------------------
  9. local wereAtBorder = {}
  10. local function markAtBorder(unit, value)
  11.     wereAtBorder[unit] = value
  12. end
  13. local function wasAtBorder(unit)
  14.     return wereAtBorder[unit]
  15. end
  16. -- -----------------------------------------------------------------
  17. -- NOTE: uses 'small' and 'big' names for fishes
  18. local function selectMessage(unit, n)
  19.     if unit == small then
  20.         addm(0, 'cil-m-hlaska'..n)
  21.     elseif unit == big then
  22.         addv(0, 'cil-v-hlaska'..n)
  23.     end
  24. end
  25. -- -----------------------------------------------------------------
  26. local reportLimit = 1
  27. local reportRate = 0
  28. local lastMessage = random(4)
  29. local function reportBorder(unit)
  30.     local result = false
  31.     reportRate = reportRate + 1
  32.     if reportRate == reportLimit then
  33.         reportLimit = reportLimit + 1
  34.         reportRate = random(reportLimit)
  35.         local message = random(3)
  36.         if message == lastMessage then
  37.             message = 3
  38.         end
  39.         lastMessage = message
  40.         selectMessage(unit, message)
  41.         result = true
  42.     end
  43.     return result
  44. end
  45.  
  46. -- -----------------------------------------------------------------
  47. local loaded = false
  48. function stdBorderReportLoad()
  49.     if not loaded then
  50.         loaded = true
  51.         dialogLoad("script/share/border_", "sound/share/border/")
  52.     end
  53. end
  54. -- -----------------------------------------------------------------
  55. function stdBorderReport()
  56.     stdBorderReportLoad()
  57.     local reported = false
  58.     local oneTry = true
  59.     if canReport() then
  60.         for index, unit in pairs(getUnitTable()) do
  61.             if unit:isAtBorder() then
  62.                 if oneTry and not wasAtBorder(unit) then
  63.                     oneTry = false
  64.                     reported = reportBorder(unit)
  65.                 end
  66.                 markAtBorder(unit, true)
  67.             else
  68.                 markAtBorder(unit, false)
  69.             end
  70.         end
  71.     end
  72.     return reported
  73. end
  74.  
  75.